package cn.edu.jdbc;

import cn.edu.jdbc.util.JdbcUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 查询用户信息
 * ResultSet executeQuery(String sql) throws SQLException;
 */
public class JdbcDemo08 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            conn = JdbcUtil.getConn();
            st = conn.createStatement();
            String sql = "select * from mydb01";
            rs = st.executeQuery(sql);
            while (rs.next()){
//                int id = rs.getInt("id");
                int id = rs.getInt("id");
                String username = rs.getString("username");
                String password = rs.getString("password");
                String nickname = rs.getString("nickname");
                int age = rs.getInt("age");
                System.out.println(id+"," + username + "," + password + "," + nickname + "," + age);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.close(rs, st, conn);
        }
    }
}
